function register() {
    //获取登录数据
    let username = $("#username").val();
    let password = $("#password").val();
    if (username != "" && password != "" && usernameCheck() && confirmPassword()) {
        //将数据转发给后台
        let data = {
            "username": username,
            "password": password
        };
        let result = myAjax("/user/addUser", "post", data, 'json');
        console.log(result);
        if (result == 200) {
            alert("注册成功");
            window.location.href = "../html/login.html";
        } else if (result==500)
            alert("内部服务器错误");
        else {
            $("#tips").html("注册信息输入有误，请重新输入");
        }
    }
}
function confirmPassword() {
    if ($("#confirmPassword").val() == "") {
        $("#psd_cfm_tips").html("确认密码不能为空");
        return  false;
    } else {
        if ($("#password").val() != $("#confirmPassword").val()) {
            $("#psd_cfm_tips").html("两次密码输入不一致，请重新输入!");
            return  false;
        } else{
            $("#psd_cfm_tips").html("");
            return true;
        }
    }
}
//用户名查重
function usernameCheck() {
    let username = $("#username").val();
    console.log(username);
    let data = myAjax("/user/getUserByUsername", "post", {"username": username}, "json");
    if (data.code==200){
        $("#unm_tips").html("");
        return true;
}if (data.code == 500) {//如果不为空，则该用户名被已占用，true
        $("#unm_tips").html("该用户编号已存在，请重新输入用户名！");
         return false;
    } else {
        $("#unm_tips").html("");
        return false;
    }
}